package org.speed.jdk;

import java.util.Random;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.LinkedBlockingQueue;

public class LinkedBlockingDequeDemo {
	
	
	public static void main(String[] args) {
		
		
		//LinkedBlockingDeque<String> qBlockingDeque = new LinkedBlockingDeque<String>();
		
		LinkedBlockingQueue<String> qBlockingDeque = new LinkedBlockingQueue<String>();
		new Thread(new Runnable() {
			
			@Override
			public void run() {
				
				long start = System.currentTimeMillis();
				
				for (int i = 0 ; i < 1000 ; i ++ ) {
					try {
						String obj = "string-" + i;
						qBlockingDeque.put(obj);
						System.out.println("===========>" + obj);
						//Thread.sleep(new Random().nextInt(1));
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
				}
				
				long end = System.currentTimeMillis();
				
				System.out.println("insert time=" + (end - start) + "ms");
			}
		}).start();
		
		
		new Thread(new Runnable() {
			
			@Override
			public void run() {
				
				String obj = null;
				try {
					while ((obj = qBlockingDeque.take()) != null) {
						//System.out.println("<===========" + obj);
					}
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}
		}).start();
		
		
		
		
		
	}

}
